package com.ckerchina.admin.ckadmin.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ckerchina.admin.ckadmin.domain.mgr.MgrMenu;

@Repository
public class MgrMenuDAO extends AbstractDao<MgrMenu, Long> {

	public List<MgrMenu> findAllMgrMenu() {
		return this.entityManager.createQuery("SELECT o FROM MgrMenu o ORDER BY o.sortNo ASC", MgrMenu.class)
				.getResultList();
	}
	
	
//	@SuppressWarnings("unchecked")
//	public List<MgrMenu> findAllMgrMenu() {
//		String sql = "SELECT m.id,m.actortype,m.companyid,a.companyname,m.create_time,m.email,m.`name`,m.pwd,m.realname FROM mgr_user m LEFT OUTER JOIN agent_user a ON m.companyid = a.id";
//		return this.entityManager.createNativeQuery(sql, MgrMenu.class).getResultList();
////		return this.entityManager.createQuery("SELECT o FROM MgrMenu o ORDER BY o.sortNo ASC", MgrMenu.class)
////				.getResultList();
//		
//	}

	public MgrMenu findBySortNo(Integer sortNo) {
		List<MgrMenu> list = this.entityManager
				.createQuery("SELECT o FROM MgrMenu o WHERE o.sortNo = ?", MgrMenu.class).setParameter(1, sortNo)
				.getResultList();
		return list.size() > 0 ? list.get(0) : null;
	}

	public Integer findMaxSortNo() {
		return entityManager.createQuery("SELECT COALESCE(MAX(o.sortNo),0) FROM MgrMenu o", Integer.class)
				.getSingleResult();
	}

}
